// pages/xiaofeibi/xiaofeibi.js
const app=getApp();
//获得全局js变量
var util = require('../../utils/util.js');
Page({
  data: {
    html: '',
    longitude: 0,
    latitude: 0,
    info: {},
    id: 0,
    imgs: []
  },

  onLoad(options) {
    this.setData({
      userinfo: wx.getStorageSync('user'),
      id: options.id,
      longitude: wx.getStorageSync('userlon'),
      latitude: wx.getStorageSync('userlat')
    });
    this.getinfo();
  },

  goaddress() {
    const that = this;
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        const lat = parseFloat(that.data.latitude);
        const lon = parseFloat(that.data.longitude);
        wx.openLocation({
          latitude: lat,
          longitude: lon,
          success() {
          }
        });
      }
    });
  },

  makep() {
    const phone = this.data.info.contactPhone;
    wx.makePhoneCall({
      phoneNumber: phone
    });
  },

  getinfo() {
    const that = this;
    util.httpRrquest(app.data.apiurl + 'shop/shopDetail?id='+that.data.id+'&userlon='+that.data.longitude+'&userlat='+that.data.latitude, 'GET')
    .then(function (response) {
        	var data = response.data.data;
        that.setData({
          info: data,
          html: data.detail,
          imgs: data.images,
          latitude: data.lat,
          longitude: data.lon
        });
    }, function (error) {
        console.log(error);
    });
    
  }
});